const util = require('../../utils/util.js')
Page({
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 5000,
    duration: 500,    
    kinddata: [{
      id: 0,
      name: "设备信息",
      open: true
    }, {
      id: 1,
      name: "基本信息",
      open: false
    }, {
      id: 2,
      name: "安装信息",
      open: false
    }, {
      id: 3,
      name: "负责人信息",
      open: false
    }],
    deviceid: 0,
    devicename: "供配电设备",
    listdata: [
      {
        id: 123,
        name: "维保检查记录",
        type: "维保检查",
        inspector: "王五",
        datetime: "2017/10/11 19:10:11",
        result: "发动机异常",
        memo: "发动机异响",
        images: ["http://sx.bzpt.edu.cn/picture/article/91/da/c0/abb3c72c4109be00ebc147fee07d/7b2d680a-dcd5-476f-9504-3e241c5887c8.jpg", "http://file03.sg560.com/upimg01/2016/04/888104/Content/1627232259035484888104.jpg"],
        open: false
      },
      {
        id: 456,
        type: "维保检查",
        name: "维保检查记录",
        inspector: "赵四",
        datetime: "2017/12/21 12:13:11",
        result: "异常",
        memo: "发动机有问题",
        images: ["http://sx.bzpt.edu.cn/picture/article/91/da/c0/abb3c72c4109be00ebc147fee07d/7b2d680a-dcd5-476f-9504-3e241c5887c8.jpg", "http://file03.sg560.com/upimg01/2016/04/888104/Content/1627232259035484888104.jpg"],
        open: false
      }
    ]
  },
  kindToggle: function (e) {
    var id = e.currentTarget.id, list = this.data.kinddata;
    for (var i = 0, len = list.length; i < len; ++i) {
      if (list[i].id == id) {
        list[i].open = !list[i].open;
      } else {
        list[i].open = false;
      }
    }
    this.setData({
      kinddata: list
    });
  },
  recordToggle: function (e) {
    var id = e.currentTarget.id, list = this.data.listdata;
    for (var i = 0, len = list.length; i < len; ++i) {
      if (list[i].id == id) {
        list[i].open = !list[i].open;
      } else {
        list[i].open = false;
      }
    }
    this.setData({
      listdata: list
    });
  },
  tabAddRecord: function () {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否自动添加测试数据',
      success: function (res) {
        if (res.confirm) {
          that.addRecord();
        } else {
          //跳转至填写页面
          wx.navigateTo({
            url: '../fault/add'
          })
        }
      }
    })
  },
  addRecord: function () {
    //添加数据
    var d = util.formatTime(new Date());
    var item = {
      id: util.randomFrom(0, 1000),
      type: "维保检查",
      name: "维保检查记录",
      inspector: "罗六",
      datetime: d,
      result: "异常",
      memo: "发动机有问题",
      images: ["http://sx.bzpt.edu.cn/picture/article/91/da/c0/abb3c72c4109be00ebc147fee07d/7b2d680a-dcd5-476f-9504-3e241c5887c8.jpg", "http://file03.sg560.com/upimg01/2016/04/888104/Content/1627232259035484888104.jpg"],
      open: false
    }
    var list = this.data.listdata;
    list.push(item);
    this.setData({
      listdata: list
    })
  }
})
